package utool

import (
	"fmt"
	"os/exec"
	"your-tool/internal/entity"
	"your-tool/internal/service"
)

// 获取动漫列表
func (a *App) AcgListGo(searchName string, week string, status int) H {
	m, err := service.AcgList(searchName, week, status)
	if err != nil {
		return M{
			"code": 0,
			"msg":  err.Error(),
		}
	}
	return M{
		"code": 1,
		"msg":  "success",
		"data": m,
	}
}

// 新增动漫
func (a *App) AcgCreateGo(acg *entity.AcgEntity) H {
	err := service.AcgCreate(acg)
	if err != nil {
		return M{
			"code": 0,
			"msg":  err.Error(),
		}
	}
	return M{
		"code": 1,
		"msg":  "success",
	}
}


// 查询动漫
func (a *App) AcgItemGo(id int) H {
	m, err := service.AcgItem(id)
	if err != nil {
		return M{
			"code": 0,
			"msg":  err.Error(),
		}
	}
	return M{
		"code": 1,
		"msg":  "success",
		"data": m,
	}
}

// 更新动漫
func (a *App) AcgUpdateGo(acg *entity.AcgEntity) H {
	err := service.AcgUpdate(acg)
	if err != nil {
		return M{
			"code": 0,
			"msg":  err.Error(),
		}
	}
	return M{
		"code": 1,
		"msg":  "success",
	}
}


// 打开浏览器进行搜索
func (a *App) AcgSearchGo(acgName string) {
	s := fmt.Sprintf("http://fjisu2.com/search/%s", acgName)
	exec.Command(`cmd`, `/c`, `start`, s).Start()
}